import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/lib/theme-chalk/index.css'
import App from './App.vue'
import router from '@/router'
import utils from '@/utils';
import NProgress from 'nprogress';
import "nprogress/nprogress.css"
import axios from "axios";
import locale from 'element-plus/lib/locale/lang/zh-cn';

axios.interceptors.request.use(config => {
  config.headers.Authorization = window.sessionStorage.getItem("token");
  NProgress.start();
  return config;
});

axios.interceptors.response.use(config => {
  NProgress.done();
  return config;
})

axios.defaults.baseURL = import.meta.env.VITE_APP_URL;

window.ajax = function ({url, method = 'get', params={}}) {
  if (method === 'get') return axios.get(`/${url}`, { params }).then(res => res.data);
  if (method === 'post') return axios.post(`/${url}`, params).then(res => res.data);
  if (method === 'delete') return axios.delete(`/${url}`, {params}).then(res => res.data);
};


const app = createApp(App);
app.use(ElementPlus, { locale });
app.use(utils);
app.use(router);
app.mount('#app');